#These rules lead to a procedure for designing a staircase. Our algorithm for designing a set of stairs will be to:
#1 Divide the total rise by 7 in and round the result to the nearest whole number to get the number of steps.
#2 We will then divide the total run by (the number of steps - 1) (see Fig. 2-1) to compute the run for each step.
#3 We will apply one of the formulas to see how close this pair of rise and run parameters is to the ideal.
#4 Then we will complete the same computations with one more step and one less step, and also compute the
#values of the formula for those combinations of rise and run.
#5 We will accept the combination of rise and run that best fits the formula for the ideal.

class StairCase

  #The rise for each step when creatign steps for insides like houses
  STEP_RISE_FOR_INSIDE = 7

  #The rise for each step when creating outside steps
  STEP_RISE_FOR_OUTSIDE = 6

  #lower bound in inches for simple verification forumla
  LOWER_BOUND_SIMPLE = 17

  #lower bound in inches for simple verification forumla
  UPPER_BOUND_SIMPLE = 18

  attr_reader :step_cnt, :step_rise, :step_run

  def initialize(total_rise, total_run)
    @total_rise, @total_run = total_rise.to_i(), total_run.to_i()
  end

  def design(mode)
    set_up(mode)
    calculate()
    offer_advice_simple()
  end

  private

  def set_up(mode)
    case mode
    when :FOR_OUTSIDE
      @step_rise = STEP_RISE_FOR_OUTSIDE
    when :FOR_INSIDE
      @step_rise = STEP_RISE_FOR_INSIDE
    else
      @step_rise = STEP_RISE_FOR_INSIDE
    end
  end

  def calculate()
    @step_cnt = @total_rise / @step_rise
    @step_run = @total_run / (@step_cnt - 1)
  end

  def verify_simple()
    total = @step_rise + @step_run
    if total.between?(LOWER_BOUND_SIMPLE, UPPER_BOUND_SIMPLE) then return :NO_ADVICE end
    if total < LOWER_BOUND_SIMPLE then return :SUM_LESS_ADVICE end
    if total > UPPER_BOUND_SIMPLE then return :SUM_GREATER_ADVICE end
  end

  def offer_advice_simple()
    puts dump_statistics()
    advice = verify_simple()
    case advice
    when :NO_ADVICE
      puts "The design seems to be stable."
    when :SUM_LESS_ADVICE
      puts "The sum of step rise and run is less than expected!"
    when :SUM_GREATER_ADVICE
      puts "The sum of step rise and run is more than expected!"
    end
  end 

  def to_s
    "Total rise: #{@total_rise}, Total run: #{@total_run}, # of steps:\
#{@step_cnt}, Step rise: #{@step_rise}, Step run: #{@step_run}"
  end

  alias :dump_statistics :to_s

end

#480,960
s = StairCase.new(ARGV[0], ARGV[1])
s.design(ARGV[2].to_sym())

arr = [23, 43, 2, 23, 44, 12, 545, 23, 66, 32]

(1..arr.size).each do |x|
  (x - 1, 0).each do |y|
    
  end
end

(1..3).each_with_index do |x, idx|
  puts "at pos #{idx} => #{x}"
end
